package com.zzccyy.jpdemo.page

import android.text.TextUtils
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import com.zzccyy.jpdemo.R
import com.zzccyy.jpdemo.base.BasicBaseActivity
import com.zzccyy.jpdemo.utils.HttpUtils
import com.zzccyy.jpdemo.utils.HttpUtils.HttpCallback

class FkActivity : BasicBaseActivity(), View.OnClickListener {
    private var tvB: TextView? = null
    private var ivClose: ImageView? = null
    private var et1: EditText? = null
    private var et2: EditText? = null

    override val layoutId: Int
        get() = R.layout.activity_fk

    override fun findViews() {
        ivClose = findViewById(R.id.ivClose)
        et1 = findViewById(R.id.et1)
        et2 = findViewById(R.id.et2)
        tvB = findViewById(R.id.tvB)
    }

    override fun setListener() {
        ivClose!!.setOnClickListener(this)

        tvB!!.setOnClickListener(this)
    }


    override fun onClick(v: View) {
        super.onClick(v)
        when (v.id) {
            R.id.ivClose -> finish()
            R.id.tvB -> {
                if (TextUtils.isEmpty(et1!!.text.toString())) {
                    Toast.makeText(this@FkActivity, "请输入反馈内容", Toast.LENGTH_SHORT).show()
                    return
                }
                if (TextUtils.isEmpty(et2!!.text.toString())) {
                    Toast.makeText(this@FkActivity, "请输入联系方式", Toast.LENGTH_SHORT).show()
                    return
                }
                val url = "https://api.tgelia.com/api/bus/addFeedback"
                val params: MutableMap<String, String> = HashMap()
                params["content"] = """
                    ${et1!!.text}
                    ${et2!!.text}
                    """.trimIndent()

                HttpUtils.getInstance().post(url, params, object : HttpCallback {
                    override fun onSuccess(result: String) {
                        finish()
                        Toast.makeText(this@FkActivity, "反馈成功", Toast.LENGTH_SHORT).show()
                    }

                    override fun onFailure(errorMsg: String) {
                        Toast.makeText(this@FkActivity, "请求失败", Toast.LENGTH_SHORT).show()
                    }
                })
            }
        }
    }


    override fun initData() {
    }
}